﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml.Linq;
using HigLabo.WindowsAzure.RestService.Extensions;

namespace HigLabo.WindowsAzure.RestService.ServiceManagement
{
    public class RoleInstance
    {
        public static readonly String ElementName = "RoleInstance";

        public String RoleName { get; private set; }
        public String InstanceName { get; private set; }
        public InstanceStatus InstanceStatus { get; private set; }
        public String InstanceUpgradeDomain { get; private set; }
        public String InstanceFaultDomain { get; private set; }
        public InstanceSize InstanceSize { get; private set; }
        public String InstanceStateDetails { get; private set; }
        public InstanceErrorCode InstanceErrorCode { get; private set; }

        public RoleInstance(XElement xml)
        {
            if (xml == null)
            {
                throw new ArgumentNullException("xml");
            }
            this.RoleName = xml.ValueOrEmpty("RoleName");
            this.InstanceName = xml.ValueOrEmpty("InstanceName");
            this.InstanceStatus = xml.ValueToEnum("InstanceStatus", InstanceStatus.RoleStateUnknown);
            this.InstanceUpgradeDomain = xml.ValueOrEmpty("InstanceUpgradeDomain");
            this.InstanceFaultDomain = xml.ValueOrEmpty("InstanceFaultDomain");
            this.InstanceSize = xml.ValueToEnum("InstanceSize", InstanceSize.Medium);
            this.InstanceStateDetails = xml.ValueOrEmpty("InstanceStateDetails");
            this.InstanceErrorCode = xml.ValueToEnum("InstanceSize", InstanceErrorCode.None);
        } 

    }
}
